package com.demo.controller.airroute;

import com.demo.common.model.Aircraft;
import com.demo.common.model.Airroute;
import com.demo.controller.aircraft.AircraftValidator;
import com.demo.interceptor.WebInterceptor;
import com.demo.service.AircraftService;
import com.demo.service.AirrouteService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;

/**
 * 飞机航线管理
 */
@Before(WebInterceptor.class)
public class AirrouteController extends Controller {

    @Inject
    AirrouteService airrouteService;

    public void index() {
        Kv cond=Kv.create();
        if(StrKit.notBlank(getPara("airrouteno"))){
            cond.set("airrouteno",getPara("airrouteno"));
        }
        if(StrKit.notBlank(getPara("begin"))){
            cond.set("begin",getPara("begin"));
        }
        if(StrKit.notBlank(getPara("end"))){
            cond.set("end",getPara("end"));
        }
        setAttr("airroutePage", airrouteService.paginate(getParaToInt(0, 1), 10,Kv.by("cond",cond)));
        render("airroute.html");
    }

    public void add() {
    }

    /**
     * save 与 update 的业务逻辑在实际应用中也应该放在 serivce 之中，
     * 并要对数据进正确性进行验证，在此仅为了偷懒
     */
    @Before(AirrouteValidator.class)
    public void save() {
        getBean(Airroute.class).save();
        redirect("/airroute");
    }

    public void edit() {
        setAttr("airroute", airrouteService.findById(getParaToInt()));
    }

    /**
     * save 与 update 的业务逻辑在实际应用中也应该放在 serivce 之中，
     * 并要对数据进正确性进行验证，在此仅为了偷懒
     */
    @Before(AirrouteValidator.class)
    public void update() {
        getBean(Airroute.class).update();
        redirect("/airroute");
    }


    public void delete() {
        airrouteService.deleteById(getParaToInt());
        redirect("/airroute");
    }
}
